#include "CLogWarpper.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"


#include <cassert>



CLogWarpper* CLogWarpper::GetInstance()
{
	static CLogWarpper _singleton;
	return &_singleton;
}

void CLogWarpper::InitLog(std::string logger_name, std::string file_name, bool multi_thread, bool debug_flag , bool info_flag )
{
	if (nullptr == m_logger)
	{
		m_debug_flag = debug_flag;
		m_info_flag = info_flag;
		if (multi_thread)
			m_logger = spdlog::daily_logger_mt(logger_name, file_name,12);
		else
			m_logger = spdlog::daily_logger_st(logger_name, file_name,12);
		assert(m_logger);
		m_logger->set_level(spdlog::level::trace);
		m_logger->flush_on(spdlog::level::trace);
	}
}

auto CLogWarpper::GetLogger()
{
	return m_logger;
}

void CLogWarpper::WriteDebugLog(QStringView log)
{
	if (m_debug_flag)
	{
		if (m_logger)
		{
			m_logger->debug(log.toString().toStdString());
		}
	}
}

void CLogWarpper::WriteInfoLog(QStringView log)
{
	if (m_info_flag)
	{
		if (m_logger)
		{
			m_logger->info(log.toString().toStdString());
		}
	}
}

CLogWarpper::CLogWarpper()
	:m_logger{}
	, m_debug_flag{true}
	, m_info_flag{ true }
{

}

CLogWarpper::~CLogWarpper()
{

}
